﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
using Pong_Project.Game_objects;

namespace Pong_Project.Views
{
    class Winner : View
    {
        private SpriteFont winnerText, pressEnter;
        private static Player winner;

        public Winner()
            : base()
        {
        }

        public static void DeclareWinner(Player player)
        {
            winner = player;
            ViewManager.State = GameState.Winner;
        }

        public override void LoadContent(ContentManager content)
        {
            winnerText = content.Load<SpriteFont>("Winner");
            pressEnter = content.Load<SpriteFont>("PressEnter");
        }

        public override void Update(GameTime gameTime)
        {
            if (Controls.MuteSound)
            {
                MediaPlayer.IsMuted = !MediaPlayer.IsMuted;
            }

            if (Controls.Enter)
            {
                ViewManager.State = GameState.Menu;
               
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            string s;
            switch (winner.Identity)
            {
                case PlayerIdentity.PlayerLeft:
                    s = "Left";
                    break;
                case PlayerIdentity.PlayerRight:
                    s = "Right";
                    break;
                default:
                    throw new ArgumentException("Invalid winner identity: " + winner.Identity);
            }
            spriteBatch.DrawString(winnerText, s + " player wins!", new Vector2(Game.WindowWidth / 4, Game.WindowHeight / 3), Color.White);
            spriteBatch.DrawString(pressEnter, "Press enter to continue", new Vector2(Game.WindowWidth / 3, Game.WindowHeight * 2 / 3), Color.Red);
        }
    }
}
